package com.yuexunit.operationman.nbsy.module.SurgicalReceipt.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.base.ExitApplication;
import com.yuexunit.operationman.nbsy.base.SubmitBean;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.SafeOperation.bean.SignBean;
import com.yuexunit.operationman.nbsy.module.SafeOperation.model.impl.SafeOperationSignModel;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.ISafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.impl.SafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.ui.view.ISafeOperationSignView;
import com.yuexunit.operationman.nbsy.module.SurgicalReceipt.Bean.SurgicalReceiptBean;
import com.yuexunit.operationman.nbsy.module.SurgicalReceipt.model.impl.SurgicalReceiptModel;
import com.yuexunit.operationman.nbsy.module.SurgicalReceipt.presenter.ISurgicalReceiptPresenter;
import com.yuexunit.operationman.nbsy.module.SurgicalReceipt.presenter.impl.SurgicalReceiptPresenter;
import com.yuexunit.operationman.nbsy.module.SurgicalReceipt.ui.view.ISurgicalReceiptView;
import com.yuexunit.operationman.nbsy.widget.ActionSheetDialog;
import com.yuexunit.operationman.nbsy.widget.ClickDialog;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;
import com.yuexunit.operationman.nbsy.widget.LoginDialog;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/7/25 0025.
 */

public class Act_SurgicalReceipt_Ward extends BaseKJActivity implements ISurgicalReceiptView ,ISafeOperationSignView {

    @Bind(R.id.tv_patient_name)
    TextView tvPatientName;
    @Bind(R.id.tv_patient_sex)
    TextView tvPatientSex;
    @Bind(R.id.tv_patient_visitno)
    TextView tvPatientVisitno;
    @Bind(R.id.tv_patient_disease)
    TextView tvPatientDisease;
    @Bind(R.id.surgical_site_marking)
    CheckBox surgicalSiteMarking;
    @Bind(R.id.preserved_skin)
    CheckBox preservedSkin;
    @Bind(R.id.check_skin_prepare)
    CheckBox checkSkinPrepare;
    @Bind(R.id.preoperative_area)
    CheckBox preoperativeArea;
    @Bind(R.id.preoperative_advice)
    CheckBox preoperativeAdvice;
    @Bind(R.id.fasting_6)
    CheckBox fasting6;
    @Bind(R.id.drinking_2)
    CheckBox drinking2;
    @Bind(R.id.drug_allergy)
    CheckBox drugAllergy;
    @Bind(R.id.radio_01)
    RadioButton radio01;
    @Bind(R.id.radio_02)
    RadioButton radio02;
    @Bind(R.id.remark)
    EditText remark;
    @Bind(R.id.goods_01)
    CheckBox goods01;
    @Bind(R.id.goods_02)
    CheckBox goods02;
    @Bind(R.id.goods_03)
    CheckBox goods03;
    @Bind(R.id.goods_04)
    CheckBox goods04;
    @Bind(R.id.goods_05)
    CheckBox goods05;
    @Bind(R.id.goods_04_count)
    EditText goods04Count;
    @Bind(R.id.goods_04_item)
    LinearLayout goods04Item;
    @Bind(R.id.goods_05_other)
    EditText goods05Other;
    @Bind(R.id.goods_05_item)
    LinearLayout goods05Item;
    @Bind(R.id.identity)
    CheckBox identity;
    @Bind(R.id.awareness_01)
    RadioButton awareness01;
    @Bind(R.id.awareness_02)
    RadioButton awareness02;
    @Bind(R.id.awareness_03)
    RadioButton awareness03;
    @Bind(R.id.awareness_04)
    RadioButton awareness04;
    @Bind(R.id.awareness_05)
    RadioButton awareness05;
    @Bind(R.id.content_01)
    EditText content01;
    @Bind(R.id.content_02)
    EditText content02;
    @Bind(R.id.content_03)
    EditText content03;
    @Bind(R.id.content_04)
    EditText content04;
    @Bind(R.id.pressure_sores_01)
    RadioButton pressureSores01;
    @Bind(R.id.pressure_sores_02)
    RadioButton pressureSores02;
    @Bind(R.id.pressure_sores_item_01)
    EditText pressureSoresItem01;
    @Bind(R.id.pressure_sores_item_02)
    EditText pressureSoresItem02;
    @Bind(R.id.pressure_sores_item)
    LinearLayout pressureSoresItem;
    @Bind(R.id.blood_product_01)
    RadioButton bloodProduct01;
    @Bind(R.id.blood_product_02)
    RadioButton bloodProduct02;
    @Bind(R.id.pipeline_01)
    RadioButton pipeline01;
    @Bind(R.id.pipeline_02)
    RadioButton pipeline02;
    @Bind(R.id.pipeline_item)
    LinearLayout pipelineItem;
    @Bind(R.id.pipeline_02_01)
    CheckBox pipeline0201;
    @Bind(R.id.pipeline_02_02)
    CheckBox pipeline0202;
    @Bind(R.id.pipeline_02_03)
    CheckBox pipeline0203;
    @Bind(R.id.pipeline_02_04)
    CheckBox pipeline0204;
    @Bind(R.id.pipeline_02_05)
    CheckBox pipeline0205;
    @Bind(R.id.pipeline_02_06)
    CheckBox pipeline0206;
    @Bind(R.id.pipeline_02_07)
    CheckBox pipeline0207;
    @Bind(R.id.pipeline_02_08)
    CheckBox pipeline0208;
    @Bind(R.id.pipeline_02_09)
    CheckBox pipeline0209;
    @Bind(R.id.pipeline_02_01_length)
    EditText pipeline0201Length;
    @Bind(R.id.pipeline_02_01_item)
    LinearLayout pipeline0201Item;
    @Bind(R.id.pipeline_02_06_count)
    EditText pipeline0206Count;
    @Bind(R.id.pipeline_02_06_item)
    LinearLayout pipeline0206Item;
    @Bind(R.id.pipeline_other)
    EditText pipelineOther;
    @Bind(R.id.oxygen_00)
    RadioButton oxygen00;
    @Bind(R.id.oxygen_01)
    RadioButton oxygen01;
    @Bind(R.id.oxygen_02)
    RadioButton oxygen02;
    @Bind(R.id.oxygen_03)
    RadioButton oxygen03;
    @Bind(R.id.oxygen_04)
    RadioButton oxygen04;
    @Bind(R.id.oxygen_05)
    RadioButton oxygen05;
    @Bind(R.id.oxygen_06)
    RadioButton oxygen06;
    @Bind(R.id.other)
    EditText other;

    //签名
    @Bind(R.id.img_so_sign_ward)
    ImageView imgSoSignWard;
    @Bind(R.id.btn_so_sign_ward)
    TextView btnSoSignWard;
    @Bind(R.id.tv_so_sign_ward_time)
    TextView tvSoSignWardTime;
    @Bind(R.id.tv_so_sign_ward_name)
    TextView tvSoSignWardName;
    @Bind(R.id.img_so_sign_opration)
    ImageView imgSoSignOpration;
    @Bind(R.id.btn_so_sign_opration)
    TextView btnSoSignOpration;
    @Bind(R.id.tv_so_sign_opration_time)
    TextView tvSoSignOprationTime;
    @Bind(R.id.tv_so_sign_opration_name)
    TextView tvSoSignOprationName;


    LoadingDialog loadingDialog;
    ISurgicalReceiptPresenter presenter;

    LoginDialog loginDialog;
    private int type = -1;
    ISafeOperationSignPresenter presenter_sign;

    ClickDialog dialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_surgicalreceipt_ward);
        ButterKnife.bind(this);
        ExitApplication.getInstance().addActivity(this);
    }

    @Override
    public void initData() {
        super.initData();
        loginDialog = new LoginDialog(aty);
        loadingDialog = new LoadingDialog(this);
        presenter = new SurgicalReceiptPresenter(this, new SurgicalReceiptModel());
        presenter_sign = new SafeOperationSignPresenter(this, new SafeOperationSignModel());
        setTitle();
        setContent();
    }

    private void setTitle() {
        tvPatientName.setText(AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getPatientName());
        if (AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getPatientSex().equals("1")) {
            tvPatientSex.setText("男");
        } else if (AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getPatientSex().equals("2")) {
            tvPatientSex.setText("女");
        } else {
            tvPatientSex.setText("不详");
        }
        tvPatientVisitno.setText("住院号" + AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getInHospitalNo());
        tvPatientDisease.setText(AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getDiagnosis());
    }

    private void setContent() {
        if (AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsWardNurseUrl() != null) {
            imgSoSignWard.setVisibility(View.VISIBLE);
            btnSoSignWard.setVisibility(View.GONE);
            tvSoSignWardTime.setVisibility(View.VISIBLE);
            tvSoSignWardName.setVisibility(View.VISIBLE);
            Glide.with(aty)
                    .load(AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsWardNurseUrl())
                    .placeholder(R.color.white)
                    .error(R.color.white)
                    .into(imgSoSignWard);
            tvSoSignWardTime.setText("签名时间:" + AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsWardNurseTimeStr());
            tvSoSignWardName.setText(AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsWardNurse());
        }
        if (AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsOrNurseUrl() != null) {
            imgSoSignOpration.setVisibility(View.VISIBLE);
            btnSoSignOpration.setVisibility(View.GONE);
            tvSoSignOprationTime.setVisibility(View.VISIBLE);
            tvSoSignOprationName.setVisibility(View.VISIBLE);
            Glide.with(aty)
                    .load(AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsOrNurseUrl())
                    .placeholder(R.color.white)
                    .error(R.color.white)
                    .into(imgSoSignOpration);
            tvSoSignOprationTime.setText("签名时间:" + AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsOrNurseTimeStr());
            tvSoSignOprationName.setText(AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsOrNurse());
        }

        for (SurgicalReceiptBean.ObjectEntity.HandoverItemListEntity p : AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList()) {
            switch (p.getItemCode()) {
                case "BS_First":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            surgicalSiteMarking.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            preservedSkin.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            checkSkinPrepare.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            preoperativeArea.setChecked(true);
                        }
                        if (skin[4].equals("1")) {
                            preoperativeAdvice.setChecked(true);
                        }
                        if (skin[5].equals("1")) {
                            fasting6.setChecked(true);
                        }
                        if (skin[6].equals("1")) {
                            drinking2.setChecked(true);
                        }
                        if (skin[7].equals("1")) {
                            drugAllergy.setChecked(true);
                        }
                    }
                    break;
                case "BS_ShiWuQueRen":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio01.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio02.setChecked(true);
                        }

                        remark.setText(skin[2]);
                    }
                    break;
                case "BS_DaiRuWuPin":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            goods01.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            goods02.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            goods03.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            goods04.setChecked(true);
                            goods04Item.setVisibility(View.VISIBLE);
                            goods04Count.setText(skin[5]);
                        }
                        if (skin[4].equals("1")) {
                            goods05.setChecked(true);
                            goods05Item.setVisibility(View.VISIBLE);
                            goods05Other.setText(p.getItemOther());
                        }
                    }
                    break;
                case "BS_ShenFenQueRen":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            identity.setChecked(true);
                        }
                    }
                    break;
                case "BS_YiShi":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            awareness01.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            awareness02.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            awareness03.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            awareness04.setChecked(true);
                        }
                        if (skin[4].equals("1")) {
                            awareness05.setChecked(true);
                        }
                    }
                    break;
                case "BS_T":
                    if (p.getItemOther().length() > 0) {
                        content01.setText(p.getItemOther());
                    }
                    break;
                case "BS_P":
                    if (p.getItemOther().length() > 0) {
                        content02.setText(p.getItemOther());
                    }
                    break;
                case "BS_R":
                    if (p.getItemOther().length() > 0) {
                        content03.setText(p.getItemOther());
                    }
                    break;
                case "BS_BP":
                    if (p.getItemOther().length() > 0) {
                        content04.setText(p.getItemOther());
                    }
                    break;
                case "BS_YaChuang":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            pressureSores01.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            pressureSores02.setChecked(true);
                            pressureSoresItem.setVisibility(View.VISIBLE);
                            pressureSoresItem01.setText(skin[2]);
                            pressureSoresItem02.setText(skin[3]);
                        }
                    }
                    break;
                case "BS_XueZhiPin":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            bloodProduct01.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            bloodProduct02.setChecked(true);
                        }
                    }
                    break;
                case "BS_Guandao":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            pipeline01.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            pipeline02.setChecked(true);
                            pipelineItem.setVisibility(View.VISIBLE);
                            if (skin[2].equals("1")) {
                                pipeline0201.setChecked(true);
                                pipeline0201Item.setVisibility(View.VISIBLE);
                                pipeline0201Length.setText(skin[11]);
                            }
                            if (skin[3].equals("1")) {
                                pipeline0202.setChecked(true);
                            }
                            if (skin[4].equals("1")) {
                                pipeline0203.setChecked(true);
                            }
                            if (skin[5].equals("1")) {
                                pipeline0204.setChecked(true);
                            }
                            if (skin[6].equals("1")) {
                                pipeline0205.setChecked(true);
                            }
                            if (skin[7].equals("1")) {
                                pipeline0206.setChecked(true);
                                pipeline0206Item.setVisibility(View.VISIBLE);
                                pipeline0206Count.setText(skin[12]);
                            }
                            if (skin[8].equals("1")) {
                                pipeline0207.setChecked(true);
                            }
                            if (skin[9].equals("1")) {
                                pipeline0208.setChecked(true);
                            }
                            if (skin[10].equals("1")) {
                                pipeline0209.setChecked(true);
                            }
                        }

                        if (p.getItemOther().length() > 0) {
                            pipelineOther.setText(p.getItemOther());
                        }
                    }
                    break;
                case "BS_XiYangFangShi":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            oxygen00.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            oxygen01.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            oxygen02.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            oxygen03.setChecked(true);
                        }
                        if (skin[4].equals("1")) {
                            oxygen04.setChecked(true);
                        }
                        if (skin[5].equals("1")) {
                            oxygen05.setChecked(true);
                        }
                        if (skin[6].equals("1")) {
                            oxygen06.setChecked(true);
                        }
                    }
                    break;
                case "BS_Other":
                    if (p.getItemOther().length() > 0) {
                        other.setText(p.getItemOther());
                    }
                    break;

            }
        }
    }

    @OnClick({R.id.titlebar_docadvice_img_back, R.id.surgical_site_marking, R.id.preserved_skin, R.id.check_skin_prepare,
            R.id.preoperative_area, R.id.preoperative_advice, R.id.fasting_6, R.id.drinking_2, R.id.drug_allergy,
            R.id.radio_01, R.id.radio_02, R.id.goods_01, R.id.goods_02, R.id.goods_03, R.id.goods_04, R.id.goods_05,
            R.id.identity, R.id.awareness_01, R.id.awareness_02, R.id.awareness_03, R.id.awareness_04, R.id.awareness_05,
            R.id.pressure_sores_01, R.id.pressure_sores_02, R.id.blood_product_01, R.id.blood_product_02, R.id.pipeline_01,
            R.id.pipeline_02, R.id.pipeline_02_01, R.id.pipeline_02_02, R.id.pipeline_02_03, R.id.pipeline_02_04,
            R.id.pipeline_02_05, R.id.pipeline_02_06, R.id.pipeline_02_07, R.id.pipeline_02_08, R.id.pipeline_02_09,
            R.id.oxygen_01, R.id.oxygen_02, R.id.oxygen_03, R.id.oxygen_04, R.id.oxygen_05, R.id.oxygen_06,
           R.id.sure, R.id.btn_so_sign_ward, R.id.btn_so_sign_opration})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_docadvice_img_back:
                finish();
                break;
            case R.id.surgical_site_marking:
                break;
            case R.id.preserved_skin:
                break;
            case R.id.check_skin_prepare:
                break;
            case R.id.preoperative_area:
                break;
            case R.id.preoperative_advice:
                break;
            case R.id.fasting_6:
                break;
            case R.id.drinking_2:
                break;
            case R.id.drug_allergy:
                break;
            case R.id.radio_01:
                break;
            case R.id.radio_02:
                break;
            case R.id.goods_01:
                break;
            case R.id.goods_02:
                break;
            case R.id.goods_03:
                break;
            case R.id.goods_04:
                if (goods04.isChecked()) {
                    goods04Item.setVisibility(View.VISIBLE);
                } else {
                    goods04Item.setVisibility(View.GONE);
                }
                break;
            case R.id.goods_05:
                if (goods05.isChecked()) {
                    goods05Item.setVisibility(View.VISIBLE);
                } else {
                    goods05Item.setVisibility(View.GONE);
                }
                break;
            case R.id.identity:
                break;
            case R.id.awareness_01:
                break;
            case R.id.awareness_02:
                break;
            case R.id.awareness_03:
                break;
            case R.id.awareness_04:
                break;
            case R.id.awareness_05:
                break;
            case R.id.pressure_sores_01:
                if (pressureSores01.isChecked()) {
                    pressureSoresItem.setVisibility(View.GONE);
                }
                break;
            case R.id.pressure_sores_02:
                if (pressureSores02.isChecked()) {
                    pressureSoresItem.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.blood_product_01:
                break;
            case R.id.blood_product_02:
                break;
            case R.id.pipeline_01:
                if (pipeline01.isChecked()) {
                    pipelineItem.setVisibility(View.GONE);
                }
                break;
            case R.id.pipeline_02:
                if (pipeline02.isChecked()) {
                    pipelineItem.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.pipeline_02_01:
                if (pipeline0201.isChecked()) {
                    pipeline0201Item.setVisibility(View.VISIBLE);
                } else {
                    pipeline0201Item.setVisibility(View.GONE);
                }
                break;
            case R.id.pipeline_02_02:
                break;
            case R.id.pipeline_02_03:
                break;
            case R.id.pipeline_02_04:
                break;
            case R.id.pipeline_02_05:
                break;
            case R.id.pipeline_02_06:
                if (pipeline0206.isChecked()) {
                    pipeline0206Item.setVisibility(View.VISIBLE);
                } else {
                    pipeline0206Item.setVisibility(View.GONE);
                }
                break;
            case R.id.pipeline_02_07:
                break;
            case R.id.pipeline_02_08:
                break;
            case R.id.pipeline_02_09:
                break;
            case R.id.oxygen_01:
                break;
            case R.id.oxygen_02:
                break;
            case R.id.oxygen_03:
                break;
            case R.id.oxygen_04:
                break;
            case R.id.oxygen_05:
                break;
            case R.id.oxygen_06:
                break;
            case R.id.sure:
                if(AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsOrNurse()!=null
                        &&AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getBsWardNurse()!=null) {
                    insertContent();
                }
                else {
                    dialog = new ClickDialog(aty).builder().setTxt("存在未签名,是否提交？");
                    dialog.isCancleBack(true);
                    dialog.setCallBack(new ClickDialog.ICallBack() {
                        @Override
                        public void callback(Bundle bundle) {
                            if(bundle.getInt("data") == 0){
                                insertContent();
                            } else if(bundle.getInt("data") == 1){
                                dialog.dismiss();
                            }

                        }
                    });
                    dialog.show();
                }
                break;
            case R.id.btn_so_sign_ward:
                showTypeDialog();
                type = 1;
                break;
            case R.id.btn_so_sign_opration:
                showTypeDialog();
                type = 2;
                break;
        }
    }

    private void showTypeDialog() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true);
        actionSheetDialog.addSheetItem("HIS签名", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {
                        loginDialog.builder();
                        loginDialog.show();
                        loginDialog.setCallBack(new LoginDialog.ICallBack() {
                            @Override
                            public void callback(Bundle bundle) {
                                Map<String, String> params = new HashMap<>();
                                params.put("jobNum", bundle.getString("person_num"));
                                params.put("loginPwd", bundle.getString("person_psw"));
                                presenter_sign.getSignInfo(params);
                            }
                        });
                    }
                });
        actionSheetDialog.addSheetItem("虹膜签名(暂不可用)", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {

                    }
                });
        actionSheetDialog.show();
    }

    @Override
    public void getSignInfo(SignBean signBean) {
        loginDialog.dismiss();
        if (signBean.getCode() == 200) {
            if(signBean.getObject().getDoctorType().equals("H")) {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
                Date curDate = new Date(System.currentTimeMillis());//获取当前时间
                String str = formatter.format(curDate);
                switch (type) {
                    case 1:
                        imgSoSignWard.setVisibility(View.VISIBLE);
                        Glide.with(this)
                                .load(signBean.getObject().getSignPicture())
                                .placeholder(R.color.white)
                                .error(R.color.white)
                                .into(imgSoSignWard);
                        btnSoSignWard.setVisibility(View.GONE);
//                        tvSoSignWardTime.setVisibility(View.VISIBLE);
//                        tvSoSignWardTime.setText("签名时间:" + str);
                        tvSoSignWardName.setVisibility(View.VISIBLE);
                        tvSoSignWardName.setText(signBean.getObject().getDoctorName());

                        AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().setBsWardNurse(signBean.getObject().getDoctorName());
                        AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().setBsWardNurseUrl(signBean.getObject().getSignPicture());
//                        AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().setBsWardNurseTimeStr(str);
                        break;
                    case 2:
                        imgSoSignOpration.setVisibility(View.VISIBLE);
                        Glide.with(this)
                                .load(signBean.getObject().getSignPicture())
                                .placeholder(R.color.white)
                                .error(R.color.white)
                                .into(imgSoSignOpration);
                        btnSoSignOpration.setVisibility(View.GONE);
//                        tvSoSignOprationTime.setVisibility(View.VISIBLE);
//                        tvSoSignOprationTime.setText("签名时间:" + str);
                        tvSoSignOprationName.setVisibility(View.VISIBLE);
                        tvSoSignOprationName.setText(signBean.getObject().getDoctorName());

                        AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().setBsOrNurse(signBean.getObject().getDoctorName());
                        AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().setBsOrNurseUrl(signBean.getObject().getSignPicture());
//                        AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().setBsOrNurseTimeStr(str);
                        break;
                }
            }
            else {
                ViewInject.toast("请使用护士账号进行签名");
            }
        } else {
            ViewInject.toast(signBean.getDesc());
        }
    }

    private void insertContent() {
            for (int i = 0; i < AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().size(); i++) {
                String value = "";
                switch (AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).getItemCode()) {
                    case "BS_First":
                        if (surgicalSiteMarking.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (preservedSkin.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (checkSkinPrepare.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (preoperativeArea.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (preoperativeAdvice.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (fasting6.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (drinking2.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (drugAllergy.isChecked()) {
                            value += "1";
                        }
                        AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(value);
                        break;
                    case "BS_ShiWuQueRen":
                        if (radio01.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue("1;;" + remark.getText().toString());
                        }
                        if (radio02.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";1;");
                        }
                        break;
                    case "BS_DaiRuWuPin":
                        if (goods01.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (goods02.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (goods03.isChecked()) {
                            value += "1;";
                        } else {
                            value += ";";
                        }
                        if (goods04.isChecked()) {
                            value += "1;";
                            if (goods05.isChecked()) {
                                value += "1;";
                                AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemOther(goods05Other.getText().toString());
                            } else {
                                value += ";";
                            }
                            value += goods04Count.getText().toString();
                        } else {
                            value += ";";
                            if (goods05.isChecked()) {
                                value += "1;";
                                AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemOther(goods05Other.getText().toString());
                            } else {
                                value += ";";
                            }
                        }
                        AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(value);
                        break;
                    case "BS_ShenFenQueRen":
                        if (identity.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue("1");
                        }
                        break;
                    case "BS_YiShi":
                        if (awareness01.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue("1;;;;");
                        }
                        if (awareness02.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";1;;;");
                        }
                        if (awareness03.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";;1;;");
                        }
                        if (awareness04.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";;;1;");
                        }
                        if (awareness05.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";;;;1");
                        }
                        break;
                    case "BS_T":
                        if (content01.getText().length() > 0) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemOther(content01.getText().toString());
                        }
                        break;
                    case "BS_P":
                        if (content02.getText().length() > 0) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemOther(content02.getText().toString());
                        }
                        break;
                    case "BS_R":
                        if (content03.getText().length() > 0) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemOther(content03.getText().toString());
                        }
                        break;
                    case "BS_BP":
                        if (content04.getText().length() > 0) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemOther(content04.getText().toString());
                        }
                        break;
                    case "BS_YaChuang":
                        if (pressureSores01.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue("1;;;");
                        }
                        if (pressureSores02.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";1;" + pressureSoresItem01.getText().toString()
                                    + ";" + pressureSoresItem02.getText().toString());
                        }
                        break;
                    case "BS_XueZhiPin":
                        if (bloodProduct01.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue("1;");
                        }
                        if (bloodProduct02.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";1");
                        }
                        break;
                    case "BS_Guandao":
                        if (pipeline01.isChecked()) {
                            value += "1;;;;;;;;;;;;";

                        }
                        if (pipeline02.isChecked()) {
                            value += ";1;";
                            if (pipeline0201.isChecked()) {
                                value += "1;";
                            } else {
                                value += ";";
                            }
                            if (pipeline0202.isChecked()) {
                                value += "1;";
                            } else {
                                value += ";";
                            }
                            if (pipeline0203.isChecked()) {
                                value += "1;";
                            } else {
                                value += ";";
                            }
                            if (pipeline0204.isChecked()) {
                                value += "1;";
                            } else {
                                value += ";";
                            }
                            if (pipeline0205.isChecked()) {
                                value += "1;";
                            } else {
                                value += ";";
                            }
                            if (pipeline0206.isChecked()) {
                                value += "1;";
                            } else {
                                value += ";";
                            }
                            if (pipeline0207.isChecked()) {
                                value += "1;";
                            } else {
                                value += ";";
                            }
                            if (pipeline0208.isChecked()) {
                                value += "1;";
                            } else {
                                value += ";";
                            }
                            if (pipeline0209.isChecked()) {
                                value += "1;";
                            } else {
                                value += ";";
                            }

                            if (pipeline0201.isChecked()) {
                                value += pipeline0201Length.getText().toString() + ";";
                            } else {
                                value += ";";
                            }

                            if (pipeline0206.isChecked()) {
                                value += pipeline0206Count.getText().toString() + "";
                            } else {
                                value += "";
                            }
                        }

                        AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(value);
                        if (pipelineOther.getText().toString().length() > 0) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemOther(pipelineOther.getText().toString());
                        }
                        break;
                    case "BS_XiYangFangShi":
                        if (oxygen00.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue("1;;;;;;");
                        }
                        if (oxygen01.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";1;;;;;");
                        }
                        if (oxygen02.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";;1;;;;");
                        }
                        if (oxygen03.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";;;1;;;");
                        }
                        if (oxygen04.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";;;;1;;");
                        }
                        if (oxygen05.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";;;;;1;");
                        }
                        if (oxygen06.isChecked()) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemValue(";;;;;;1");
                        }
                        break;
                    case "BS_Other":
                        if (other.getText().length() > 0) {
                            AppConfig.SURGICALRECEIPTBEAN.getObject().getHandoverItemList().get(i).setItemOther(other.getText().toString());
                        }
                        break;
                }
            }

            if (AppConfig.SURGICALRECEIPTBEAN.getObject().getTransferHandover().getHandoverId() == null) {
                Map<String, String> params = new HashMap<>();
                params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID) + "");
                params.put("saveData", JSON.toJSONString(AppConfig.SURGICALRECEIPTBEAN));
                presenter.insertSurgicalReceiptDate(params);
            } else {
                Map<String, String> params = new HashMap<>();
                params.put("accountId", PreferenceHelper.readInt(aty, AppConfig.USER_INFO, AppConfig.USER_ACCOUNT) + "");
                params.put("fullName", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.USER_FULLNAME) + "");
                params.put("saveData", JSON.toJSONString(AppConfig.SURGICALRECEIPTBEAN));
                presenter.updateSurgicalReceiptDate(params);
            }
    }

    @Override
    public void insertSurgicalReceiptDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void updateSurgicalReceiptDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }

    /**
     * 通过dispatchTouchEvent每次ACTION_DOWN事件中动态判断非EditText本身区域的点击事件，然后在事件中进行屏蔽。然后当点击不是EditText时候，进行隐藏键盘操作
     *
     * @param ev
     * @return
     */

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            if (isShouldHideInput(v, ev)) {

                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            }
            return super.dispatchTouchEvent(ev);
        }
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);
    }

    public boolean isShouldHideInput(View v, MotionEvent event) {

        if (v != null && (v instanceof EditText)) {
            int[] leftTop = {0, 0};
            //获取输入框当前的location位置
            v.getLocationInWindow(leftTop);
            int left = leftTop[0];
            int top = leftTop[1];
            int bottom = top + v.getHeight();
            int right = left + v.getWidth();
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 点击的是输入框区域，保留点击EditText的事件\
                return false;
            } else {
                return true;
            }
        }
        return false;
    }

}
